/*
 * This file is part of aion-unique <aion-unique.smfnew.com>.
 *
 *  aion-unique is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-unique is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionemu.gameserver.network.aion.clientpackets;

import com.aionemu.gameserver.model.gameobjects.NpcWhichNotGatherable;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.network.aion.AbstractAionClientPacket;
import com.aionemu.gameserver.services.TeleportService;

/**
 * @author Lyahim, ATracer, orz
 *
 */
public class CM_TELEPORT_SELECT extends AbstractAionClientPacket
{
	/** NPC ID */
	public int					targetObjectId;

	/** Destination of teleport */
	public int					locId;

	public CM_TELEPORT_SELECT(int opcode)
	{
		super(opcode);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void readImpl()
	{
		// empty
		targetObjectId = readD();
		locId = readD(); //locationId
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void runImpl()
	{
		Player activePlayer = getClient().getActivePlayer();

		NpcWhichNotGatherable npc = (NpcWhichNotGatherable)activePlayer.getKnownList().getObject(targetObjectId) ;

		if (activePlayer == null || activePlayer.getLifeStats().isAlreadyDead())
			return;
		TeleportService.teleport(npc, locId, activePlayer);
	}
}
